package com.ycy.smartcourseselection.controller;

import com.ycy.smartcourseselection.common.ResData;
import com.ycy.smartcourseselection.dto.myFile.MyFileDTO;
import com.ycy.smartcourseselection.entity.MyFile;
import com.ycy.smartcourseselection.service.MyFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@Api(tags = "文件管理")
@RestController
@RequestMapping("/file")
public class MyFileController {
    @Resource
    MyFileService myFileService;

    @PostMapping("/upload")
    @ApiOperation("上传")
    public ResData<MyFile> upload(@RequestPart MultipartFile file) {
        return myFileService.upload(file);
    }

    @GetMapping("/download")
    @ApiOperation("下载")
    public void download(@RequestParam String uniqueName, HttpServletResponse response) {
        myFileService.download(uniqueName,response);
    }

    @PostMapping("/updateAvatar")
    @ApiOperation("更换头像")
    public ResData<MyFile> updateAvatar(@RequestPart MultipartFile file, MyFileDTO myFileDTO) {
        return myFileService.updateAvatar(file,myFileDTO);
    }
}
